<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?=$this->session->config->title?></title>
    <link rel=stylesheet href="<?=base_url('public/mobile/jquery.mobile-1.4.5.min.css')?>">
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
    <script src="<?=base_url('public/mobile/jquery.mobile-1.4.5.min.js')?>"></script>
    <script src="<?=base_url('public/mobile/layer.m/layer.m.js')?>"></script>
    <script type="text/javascript" src="<?=base_url('public/lib/jqusey.form.js')?>"></script>
</head>
<body>
    <div data-role="page">

        <div data-role="header">
            <h1>用户登录</h1>
        </div>

        <div data-role="main" class="ui-content">
            <form method="post" action="<?=site_url('welcome/login') ?>" id="callAjaxForm">
                <label for="fname">用户名:</label>
                <input type="text" name="username" data-clear-btn="true">
                <label for="fname">密码:</label>
                <input type="password" name="password" data-clear-btn="true">
                <label for="fname">验证码:</label>
                <input type="text" name="cap" data-clear-btn="true">
                <label onclick="reset_cap()" id="cap" title="点击刷新验证码" for="fname"><?=$cap['image']?></label>
                <input type="submit" value="登录" id="submit">
                <input type="reset" value="重置">
            </form>
        </div>


    </div>
<script type="text/javascript">
    function reset_cap(){
        $.get("<?=site_url('welcome/reset_cap')?>",function(res){
            $("#cap").html(res);
        });
    }
    function onSuccess(data, status)
    {
        if(data == 1){
            location.href="<?= site_url('home/index')?>";
        }else{
            layer.open({
                content: data,
                style:'width:100%',
                btn: ['确定']
            });
        }
    }

    function onError(data, status)
    {
        alert(data);
    }

    $(document).ready(function() {
        $("#submit").click(function(){

            var formData = $("#callAjaxForm").serialize();

            $.ajax({
                type: "POST",
                url: "<?=site_url('welcome/login') ?>",
                cache: false,
                data: formData,
                success: onSuccess,
                error: onError
            });

            return false;
        });
    });
</script>
</body>
</html>